home *** CD-ROM | disk | FTP | other *** search
/ World of Education / World of Education.iso / world_m / mercuryz.zip / GCD.C < prev    next >
C/C++ Source or Header  |  1992-03-24  |  655b  |  42 lines

  1.  
  2. /* Gcd.c
  3.  
  4. compute GCD using Euclid Algorithm
  5.  
  6. eg, GCD 156562431911123 442677773754356 = 7
  7.  
  8. Source to GCD.BIN.  Rebuild with Borland C++:
  9.  
  10.     bcc -c -mt! gcd
  11.     tlink x02 gcd /t/x/c,gcd.bin,,fp ld
  12.  
  13. If you are using a coprocessor, you can also build with:
  14.  
  15.     bcc -c -mt! gcd
  16.     tlink x01 gcd f87 /t/x/c,gcd.bin,,fp ld
  17.  
  18. With older versions of Borland C++ (Turbo C), compile with:
  19.  
  20.     tcc -c -mt gcd
  21. */
  22.  
  23. #include "mathl.h"
  24.  
  25. long double gcd(long double x, long double y)
  26. {
  27.     long double z;
  28.     do
  29.     {
  30.         z = fmodl(x,y);
  31.         x = y;
  32.         y = z;
  33.     }
  34.     while (z != 0);
  35.     return x;
  36. }
  37.  
  38. void pascal xmain(double far *x)
  39. {
  40.     x[0] = gcd(x[1],x[2]);
  41. }
  42.